<?php

namespace App\Service;

use App\Model\AdjacentKitchenModel;
use App\Model\AdjacentOlderModel;
use App\Model\AdjacentSchoolModel;
use App\Model\AdjacentToolModel;
use App\Model\ConfigShareItemModel;
use App\Model\ExamineAdjacentKitchenModel;
use App\Model\ExamineAdjacentOlderModel;
use App\Model\ExamineAdjacentSchoolModel;
use App\Model\OrderModel;
use App\Model\ShareKitchenToolModel;
use App\Model\ShareLatticeCommentModel;
use App\Model\ShareLatticeGoodModel;
use App\Model\ShareLatticeGoodsModel;
use App\Model\ShareLatticeModel;
use App\Model\ShareLatticeOrderModel;
use App\Model\ShareLatticeSeeModel;
use App\Model\ShareToolNavModel;
use App\Model\ShareTopicModel;
use App\Model\StaffModel;
use App\Model\UserModel;
use App\Utility\DataConversion;
use App\Utility\Payment;
use EasySwoole\ORM\Exception\Exception;
use Throwable;

class ShareService extends BaseService
{
    /**
     * @param $limit
     * @param $page
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function getTopic($limit, $page): array
    {
        $model = ShareTopicModel::create();
        $model->limit($limit * ($page - 1), $limit)->withTotalCount();
        $list = $model->all(['is_deleted' => 0]);
        $result = $model->lastQueryResult();
        // 总条数
        $total = $result->getTotalCount();

        if (empty($list)) {
            return [
                'result' => false,
                'msg' => '暂无更多分类'
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $list
        ];
    }

    /**
     * @param $uid
     * @param $nid
     * @param $house
     * @param $child_name
     * @param $child_grade
     * @param $child_hobby
     * @param $child_age
     * @param $name
     * @param $tel
     * @param $name1
     * @param $tel1
     * @param $start_time
     * @param $end_time
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function schoolJoin($uid, $nid, $house, $child_name, $child_grade, $child_hobby, $child_age, $name, $tel, $name1, $tel1, $start_time, $end_time): array
    {
        $par = [
            'uid' => $uid,
            'nid' => $nid,
            'house' => $house,
            'child_name' => $child_name,
            'child_grade' => $child_grade,
            'child_hobby' => $child_hobby,
            'child_age' => $child_age,
            'name' => $name,
            'name1' => $name1,
            'tel' => $tel,
            'tel1' => $tel1,
            'start_time' => strtotime($start_time),
            'end_time' => strtotime($end_time)
        ];

        $res = AdjacentSchoolModel::create()->addAdjacent($par);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '提交失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '提交成功',
            'data' => 'success'
        ];
    }

    /**
     * @param $uid
     * @param $nid
     * @param $house
     * @param $older_name
     * @param $older_age
     * @param $older_sex
     * @param $name
     * @param $tel
     * @param $start_time
     * @param $end_time
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function oldJoin($uid, $nid, $house, $older_name, $older_age, $older_sex, $name, $tel, $start_time, $end_time): array
    {
        $par = [
            'uid' => $uid,
            'nid' => $nid,
            'house' => $house,
            'older_name' => $older_name,
            'older_age' => $older_age,
            'older_sex' => $older_sex,
            'name' => $name,
            'tel' => $tel,
            'start_time' => strtotime($start_time),
            'end_time' => strtotime($end_time)
        ];

        $res = AdjacentOlderModel::create()->addAdjacent($par);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '提交失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '提交成功',
            'data' => 'success'
        ];
    }

    /**
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function getTools(): array
    {
        $toold = ShareToolNavModel::create()->where(['nid' => 0, 'is_deleted' => 0])->all();
        $data = [];
        foreach ($toold as $tool) {
            $data[] = [
                'name' => $tool['name'],
                'foods' => $this->item_filter($tool['id'])
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param int $nid
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function item_filter(int $nid = 0): array
    {
        $tags = ShareToolNavModel::create()->all(['nid' => $nid, 'is_deleted' => 0]);
        $data = [];
        if (!$tags) return $data;
        foreach ($tags as $k => $tag) {
            if ($tag['nid'] == $nid)
                $data[$k] = [
                    'name' => $tag['name'],
                    'key' => $tag['name'],
                    'icon' => $tag['icon'],
                    'cat' => $tag['id'],
                    'status' => $tag['stock'] == 0 ? 0 : 1,
                    'stock' => $tag['stock']
                ];
        }
        return $data;
    }

    /**
     * @param $uid
     * @param $nid
     * @param $tools
     * @param $address
     * @param $name
     * @param $tel
     * @param $start_time
     * @param $end_time
     * @param $type
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function toolBorrow($uid, $nid, $tools, $address, $name, $tel, $start_time, $end_time, $type): array
    {
        $par = [
            'uid' => $uid,
            'nid' => json_encode($nid),
            'tools' => json_encode($tools),
            'address' => $address,
            'name' => $name,
            'tel' => $tel,
            'start_time' => strtotime($start_time),
            'end_time' => strtotime($end_time),
            'type' => $type
        ];

        $res = AdjacentToolModel::create()->addAdjacent($par);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '提交失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '提交成功',
            'data' => 'success'
        ];
    }

    /**
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function getKitchenTools(): array
    {
        $toold = ShareKitchenToolModel::create()->where(['is_deleted' => 0])->all();
        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $toold
        ];
    }

    /**
     * @param $uid
     * @param $nid
     * @param $tools
     * @param $address
     * @param $name
     * @param $tel
     * @param $start_time
     * @param $end_time
     * @param $type
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function kitchenToolBorrow($uid, $nid, $tools, $address, $name, $tel, $start_time, $end_time, $type): array
    {
        $par = [
            'uid' => $uid,
            'nid' => json_encode($nid),
            'tools' => json_encode($tools),
            'address' => $address,
            'name' => $name,
            'tel' => $tel,
            'start_time' => strtotime($start_time),
            'end_time' => strtotime($end_time),
            'type' => $type
        ];

        $res = AdjacentKitchenModel::create()->addAdjacent($par);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '提交失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '提交成功',
            'data' => 'success'
        ];
    }

    /**
     * @param $uid
     * @param $status
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getMySchool($uid, $status): array
    {
        $where = ['is_deleted' => 0, 'uid' => $uid];
        if ($status != 99) {
            $where['status'] = $status;
        }
        $model = AdjacentSchoolModel::create();
        if ($status == 1) {
            $model->where("end_time", time(), '>=');
        } elseif ($status == 3) {
            $where['status'] = 1;
            $model->where("end_time", time(), '<');
        }

        $school = $model->where($where)->order('id', 'DESC')->all();
        if (empty($school)) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $data = [];

        foreach ($school as $item) {
            $share = ConfigService::getInstance()->getServiceItem($item['nid']);
            $order = OrderModel::create()->getOrder(['uid' => $uid, 'type' => 5, 'rid' => $item['id']]);
            $data[] = [
                'id' => $item['id'],
                'nid' => $item['nid'],
                'title' => $share->name,
                'status' => $item['status'],
                'status_label' => $item['status'] != 1 ? ConfigService::getInstance()->getShareStatus($item['status']) : ($item['end_time'] >= time() ? ConfigService::getInstance()->getShareStatus($item['status']) : '已结束'),
                'memo' => $share->label,
                'time' => date("Y-m-d", $item['start_time']) . ' ~ ' . date('Y-m-d', $item['end_time']),
                'during' => DataConversion::getInstance()->getDays($item['start_time'], $item['end_time']),
                'fee' => $share->price,
                'order_no' => $order->order_no ?? '-',
                'pay' => $order->amount_real ?? '-',
                'pay_time' => $order->payment_time ?? '-'
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $status
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getMyOlder($uid, $status): array
    {
        $where = ['is_deleted' => 0, 'uid' => $uid];
        if ($status != 99) {
            $where['status'] = $status;
        }

        $model = AdjacentOlderModel::create();
        if ($status == 1) {
            $model->where("end_time", time(), '>=');
        } elseif ($status == 3) {
            $where['status'] = 1;
            $model->where("end_time", time(), '<');
        }

        $olders = $model->where($where)->order('id', 'DESC')->all();
        if (empty($olders)) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $data = [];

        foreach ($olders as $item) {
            $share = ConfigService::getInstance()->getServiceItem($item['nid']);
            $order = OrderModel::create()->getOrder(['uid' => $uid, 'type' => 5, 'rid' => $item['id']]);
            $data[] = [
                'id' => $item['id'],
                'nid' => $item['nid'],
                'title' => $share->name,
                'status' => $item['status'],
                'status_label' => $item['status'] != 1 ? ConfigService::getInstance()->getShareStatus($item['status']) : ($item['end_time'] >= time() ? ConfigService::getInstance()->getShareStatus($item['status']) : '已结束'),
                'memo' => $share->label,
                'time' => date("Y-m-d", $item['start_time']) . ' ~ ' . date('Y-m-d', $item['end_time']),
                'during' => DataConversion::getInstance()->getDays($item['start_time'], $item['end_time']),
                'fee' => $share->price,
                'order_no' => $order->order_no ?? '-',
                'pay' => $order->amount_real ?? '-',
                'pay_time' => $order->payment_time ?? '-'
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $status
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function getMyKitchen($uid, $status): array
    {
        $where = ['is_deleted' => 0, 'uid' => $uid, 'status' => $status];
        $tools = AdjacentKitchenModel::create()->where($where)->order('id', 'DESC')->all();
        if (empty($tools)) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $data = [];

        foreach ($tools as $item) {
            $data[] = [
                'id' => $item['id'],
                'nid' => $item['nid'],
                'name' => $item['name'],
                'tel' => $item['tel'],
                'address' => $item['address'],
                'tool' => implode(',', json_decode($item['tools'])),
                'title' => $item['nid'] != "0" ? '共享工具' : '共享场地',
                'status' => $item['status'],
                'status_label' => ConfigService::getInstance()->getToolsStatus($item['status']),
                'time' => date("Y-m-d", $item['start_time']) . ' ~ ' . date('Y-m-d', $item['end_time']),
                'create_time' => date("Y-m-d H:i", $item['create_time'])
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $type
     * @param $status
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function getMyTools($uid, $type, $status): array
    {
        $where = ['is_deleted' => 0, 'uid' => $uid, 'type' => $type, 'status' => $status];
        $tools = AdjacentToolModel::create()->where($where)->order('id', 'DESC')->all();
        if (empty($tools)) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $data = [];

        foreach ($tools as $item) {

            $data[] = [
                'id' => $item['id'],
                'nid' => $item['nid'],
                'name' => $item['name'],
                'tel' => $item['tel'],
                'address' => $item['address'],
                'tool' => implode(',', json_decode($item['tools'])),
                'title' => '借用工具',
                'status' => $item['status'],
                'status_label' => ConfigService::getInstance()->getToolsStatus($item['status']),
                'time' => date("Y-m-d H:i", $item['start_time']) . ' ~ ' . date('Y-m-d H:i', $item['end_time']),
                'create_time' => date("Y-m-d H:i", $item['create_time'])
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $topic
     * @param $from
     * @param $content
     * @param $images
     * @param $price
     * @param $contact_type
     * @param $contact
     * @param $location
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function release($uid, $topic, $from, $content, $images, $price, $contact_type, $contact, $location): array
    {
        $par = [
            'uid' => $uid,
            'topic' => $topic,
            'from' => $from,
            'content' => $content,
            'images' => json_encode($images),
            'location' => $location,
            'price' => doubleval($price),
            'contact_type' => $contact_type,
            'contact' => $contact
        ];

        $res = ShareLatticeModel::create()->addDynamic($par);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '发布失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '发布成功',
            'data' => 'success'
        ];
    }

    /**
     * @param $tid
     * @param $page
     * @param $limit
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getLattice($tid, $page, $limit): array
    {
        $where = ['is_deleted' => 0];
        $model = ShareLatticeModel::create();
        $model->limit($limit * ($page - 1), $limit)->withTotalCount();
        if ($tid != 99) {
            $where['topic'] = $tid;
        }

        $model->order('id', "DESC");
        $list = $model->where($where)->all();
        $result = $model->lastQueryResult();
        // 总条数
        $total = $result->getTotalCount();
        if (empty($list)) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $data = [];
        foreach ($list as $item) {
            $user = UserModel::create()->getUser(['id' => $item['uid']]);
            $data[] = [
                'id' => $item['id'],
                'avatar' => $user->avatar ?? '',
                'username' => $user->username ?? '匿名',
                'from' => $item['from'],
                'theme' => ConfigService::getInstance()->getLatticeTopic($item['topic']),
                'content' => $item['content'],
                'see' => $item['see'],
                'like' => $item['like'],
                'comment' => $item['comment'],
                'images' => json_decode($item['images'], true),
                'time' => DataConversion::getInstance()->timeToDate($item['create_time']),
                'price' => $item['price'],
                'status' => $item['status'],
                'status_label' => $item['status'] == 1 ? '已转让' : '',
                'contact_type' => $item['contact_type'],
                'contact' => $item['contact']
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $limit
     * @param $page
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getMyRelease($uid, $limit, $page): array
    {
        $where = ['is_deleted' => 0, 'uid' => $uid];
        $model = ShareLatticeModel::create();
        $model->limit($limit * ($page - 1), $limit)->withTotalCount();

        $model->order('id', "DESC");
        $list = $model->where($where)->all();
        $result = $model->lastQueryResult();
        // 总条数
        $total = $result->getTotalCount();
        if (empty($list)) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $data = [];
        foreach ($list as $item) {
            $user = UserModel::create()->getUser(['id' => $item['uid']]);
            $data[] = [
                'id' => $item['id'],
                'avatar' => $user->avatar ?? '',
                'username' => $user->username ?? '匿名',
                'from' => $item['from'],
                'theme' => ConfigService::getInstance()->getLatticeTopic($item['topic']),
                'content' => $item['content'],
                'see' => $item['see'],
                'like' => $item['like'],
                'comment' => $item['comment'],
                'images' => json_decode($item['images'], true),
                'time' => DataConversion::getInstance()->timeToDate($item['create_time']),
                'price' => $item['price'],
                'status' => $item['status'],
                'status_label' => $item['status'] == 1 ? '已转让' : '',
                'contact_type' => $item['contact_type'],
                'contact' => $item['contact']
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $gid
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function likeDynamic($uid, $gid): array
    {
        $like = ShareLatticeGoodModel::create()->getDynamic(['gid' => $gid, 'uid' => $uid]);
        if ($like) {
            return [
                'result' => false,
                'msg' => '已点赞,请勿重复操作'
            ];
        }

        $param = [
            'uid' => $uid,
            'gid' => $gid,
            'like' => 1
        ];

        $res = ShareLatticeGoodModel::create()->addDynamic($param);

        $res1 = $this->see($uid, $gid);
        if (!$res || !$res1) {
            return [
                'result' => false,
                'msg' => '操作失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '已点赞',
            'data' => $res
        ];
    }

    /**
     * @param $uid
     * @param $gid
     * @return bool
     * @throws Exception
     * @throws Throwable
     */
    public function see($uid, $gid): bool
    {
        $param = [
            'uid' => $uid,
            'gid' => $gid,
            'see' => 1
        ];

        $res = ShareLatticeSeeModel::create()->addDynamic($param);
        if (!$res) {
            return false;
        }
        return true;
    }

    /**
     * @param $uid
     * @param $gid
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getDynamicDetail($uid, $gid): array
    {
        $dynamic = ShareLatticeModel::create()->getDynamic(['id' => $gid]);
        if (!$dynamic) {
            return [
                'result' => false,
                'msg' => '该动态已删除'
            ];
        }
        if ($uid != $dynamic->uid) {
            $this->see($uid, $gid);
        }

        $user = UserModel::create()->getUser(['id' => $dynamic->uid]);
        if (!$user) {
            return [
                'result' => false,
                'msg' => '该账户已注销'
            ];
        }
        $data = [
            'id' => $gid,
            'avatar' => $user->avatar,
            'username' => $user->username,
            'date' => DataConversion::getInstance()->timeToDate($dynamic->create_time),
            'content' => $dynamic->content,
            'images' => json_decode($dynamic->images, true),
            "see" => $dynamic->see,
            "comment" => $dynamic->comment,
            'like' => $dynamic->like,
            'location' => $dynamic->location,
            'from' => $dynamic->from,
            'theme' => ConfigService::getInstance()->getLatticeTopic($dynamic->topic),
            'time' => DataConversion::getInstance()->timeToDate($dynamic->create_time),
            'price' => $dynamic->price,
            'status' => $dynamic->status,
            'status_label' => $dynamic->status == 1 ? '已转让' : '',
            'contact_type' => $dynamic->contact_type,
            'contact' => $dynamic->contact
        ];

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $gid
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getDynamicComment($uid, $gid): array
    {
        $comments = ShareLatticeCommentModel::create()->where(['gid' => $gid, 'nid' => 0, 'is_deleted' => 0])->all();
        if (empty($comments)) {
            return [
                'result' => false,
                'msg' => '暂无评论'
            ];
        }
        $data = [];
        foreach ($comments as $comment) {
            $user = UserModel::create()->getUser(['id' => $comment['uid']]);
            $data[] = [
                'id' => $comment['id'],
                'username' => $user->username,
                'avatar' => $user->avatar ?? '',
                'time' => DataConversion::getInstance()->timeToDate($comment['create_time']),
                'likeNum' => $comment['likeNum'],
                'content' => $comment['content'],
                'isLike' => false,
                'reply' => $this->comment_filter($comment['id']),
                'allReply' => count($this->comment_filter($comment['id']))
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => [
                'total' => count($data),
                'data' => $data
            ]
        ];
    }

    /**
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function comment_filter($id): array
    {
        $comments = ShareLatticeCommentModel::create()->all(['nid' => $id, 'is_deleted' => 0]);
        if (!is_array($comments) || empty($comments)) return [];
        $data = [];
        foreach ($comments as $comment) {
            $user = UserModel::create()->getUser(['id' => $comment['uid']]);
            $data[] = [
                'id' => $comment['id'],
                'username' => $user->username ?? '匿名用户',
                'avatar' => $user->avatar ?? '',
                'time' => DataConversion::getInstance()->timeToDate($comment['create_time']),
                'likeNum' => $comment['likeNum'],
                'content' => $comment['content'],
                'isLike' => false,
                'reply' => $this->comment_filter($comment['id']),
                'allReply' => count($this->comment_filter($comment['id']))
            ];
        }

        return $data;
    }

    /**
     * @param $uid
     * @param $id
     * @param $gid
     * @param $content
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function commentDynamic($uid, $id, $gid, $content): array
    {
        $param = [
            'uid' => $uid,
            'gid' => $gid,
            'content' => $content
        ];
        if ($id != 0) {
            $comment = ShareLatticeCommentModel::create()->getDynamic(['id' => $id]);
            if ($comment) {
                $param['nid'] = $id;
            }
        }

        $res = ShareLatticeCommentModel::create()->addDynamic($param);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '评论失败'
            ];
        }
        $data = $this->getDynamicComment($uid, $gid);
        return [
            'result' => true,
            'msg' => '评论成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getSchoolDetail($uid, $id): array
    {
        $school = AdjacentSchoolModel::create()->getAdjacent(['id' => $id, 'uid' => $uid]);
        if (!$school) {
            return [
                'result' => false,
                'msg' => '该订单已删除'
            ];
        }

        $school = $school->toArray();
        $share = ConfigService::getInstance()->getServiceItem($school['nid']);
        $data = [
            'id' => $school['id'],
            'nid' => $school['nid'],
            'name' => $school['name'],
            'tel' => $school['tel'],
            'house' => $school['house'],
            'child_name' => $school['child_name'],
            'child_grade' => $school['child_grade'],
            'child_hobby' => $school['child_hobby'],
            'child_age' => $school['child_age'],
            'name1' => $school['name1'],
            'tel1' => $school['tel1'],
            'title' => $share->name,
            'status' => $school['status'],
            'status_label' => ConfigService::getInstance()->getShareStatus($school['status']),
            'memo' => $share->label,
            'time' => date("Y-m-d", $school['start_time']) . ' ~ ' . date('Y-m-d', $school['end_time']),
            'during' => DataConversion::getInstance()->getDays($school['start_time'], $school['end_time']),
            'fee' => $share->price
        ];

        $examine = ExamineAdjacentSchoolModel::create()->getLog(['pid' => $school['id']]);
        $data['examine'] = $examine ? $examine->toArray() : [];

        return [
            'result' => true,
            'msg' => '查询成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getOlderDetail($uid, $id): array
    {
        $school = AdjacentOlderModel::create()->getAdjacent(['id' => $id, 'uid' => $uid]);
        if (!$school) {
            return [
                'result' => false,
                'msg' => '该订单已删除'
            ];
        }

        $school = $school->toArray();
        $share = ConfigService::getInstance()->getServiceItem($school['nid']);
        $data = [
            'id' => $school['id'],
            'nid' => $school['nid'],
            'name' => $school['name'],
            'tel' => $school['tel'],
            'house' => $school['house'],
            'older_name' => $school['older_name'],
            'older_age' => $school['older_age'],
            'older_sex' => $school['older_sex'],
            'title' => $share->name,
            'status' => $school['status'],
            'status_label' => ConfigService::getInstance()->getShareStatus($school['status']),
            'memo' => $share->label,
            'time' => date("Y-m-d", $school['start_time']) . ' ~ ' . date('Y-m-d', $school['end_time']),
            'during' => DataConversion::getInstance()->getDays($school['start_time'], $school['end_time']),
            'fee' => $share->price
        ];

        $examine = ExamineAdjacentOlderModel::create()->getLog(['pid' => $school['id']]);
        $data['examine'] = $examine ? $examine->toArray() : [];

        return [
            'result' => true,
            'msg' => '查询成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getKitchenDetail($uid, $id): array
    {
        $tools = AdjacentKitchenModel::create()->getAdjacent(['id' => $id, 'uid' => $uid]);
        if (!$tools) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $tool = $tools->toArray();
        $data = [
            'id' => $tool['id'],
            'nid' => $tool['nid'],
            'name' => $tool['name'],
            'tel' => $tool['tel'],
            'address' => $tool['address'],
            'tool' => implode(',', json_decode($tool['tools'])),
            'title' => $tool['nid'] == 0 ? '共享场地' : '共享工具',
            'status' => $tool['status'],
            'status_label' => ConfigService::getInstance()->getToolsStatus($tool['status']),
            'time' => date("Y-m-d", $tool['start_time']) . ' ~ ' . date('Y-m-d', $tool['end_time']),
            'create_time' => date("Y-m-d H:i", $tool['create_time'])
        ];

        $examine = ExamineAdjacentKitchenModel::create()->getLog(['pid' => $tool['id']]);
        $data['examine'] = $examine ? $examine->toArray() : [];

        return [
            'result' => true,
            'msg' => '查询成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function paySchool($uid, $id): array
    {
        $school = AdjacentSchoolModel::create()->getAdjacent(['id' => $id, 'uid' => $uid]);
        if (!$school) {
            return [
                'result' => false,
                'msg' => '该订单已删除'
            ];
        }

        $school = $school->toArray();
        $share = ConfigService::getInstance()->getServiceItem($school['nid']);

        $order_no = DataConversion::getInstance()->get_order_no();
        $fee = $share->price;
        $dur = DataConversion::getInstance()->getDays($school['start_time'], $school['end_time']);
        $price = $fee * $dur;
        $name = "【 " . $share->name . "报名】" . $order_no . '支付' . $price . '元';
        $orderParam = [
            'uid' => $uid,
            'rid' => $school['id'],
            'type' => 5,
            'order_no' => $order_no,
            'amount_real' => $price,
            'payment_type' => 0,
            'status' => 3,
            'order_remark' => $name
        ];

        if ($price == 0) {
            $orderParam['status'] = 4;
            $orderParam['payment_real'] = 0.00;
            $orderParam['payment_amount'] = 0.00;
            $orderParam['payment_remark'] = 'SUCCESS';
            $orderParam['payment_status'] = 1;
            $orderParam['payment_time'] = time();
            $res = AdjacentSchoolModel::create()->update(['status' => 1], ['uid' => $uid, 'id' => $id]);
            if (!$res) {
                return [
                    'result' => false,
                    'msg' => '系统错误，请稍后重试'
                ];
            }
        } else {
            $appid = ConfigService::getInstance()->getSys("mxappid", 'wepay');
            $mxappid = ConfigService::getInstance()->getSys("mxminiappid", 'wepay');
            $mchid = ConfigService::getInstance()->getSys("mchid", 'wepay');
            $password = ConfigService::getInstance()->getSys("mxpassword", 'wepay');
            $cert = ConfigService::getInstance()->getSys("cert", 'wepay');
            $key = ConfigService::getInstance()->getSys("key", 'wepay');
            $notifyUrl = ConfigService::getInstance()->getSys("wenotify_url", 'wepay');
            $user = UserModel::create()->getUser(['id' => $uid]);
            if (!$user || $user->we_code == '') {
                return [
                    'result' => false,
                    'msg' => 'openidNotFound'
                ];
            }

            $res = Payment::getInstance()->mxWepay($appid, $mxappid, $mchid, $password, $cert, $key, $user->we_code, $order_no, $price * 100, $name, $notifyUrl, $ip);
            $result = $res->toArray();
        }

        $resOrder = OrderModel::create()->addOrder($orderParam);
        if (!$resOrder) {
            return [
                'result' => false,
                'msg' => '系统错误，请稍后重试'
            ];
        }

        return [
            'result' => true,
            'msg' => '成功',
            'data' => $result ?? 'success'
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function payOlder($uid, $id): array
    {
        $school = AdjacentOlderModel::create()->getAdjacent(['id' => $id, 'uid' => $uid]);
        if (!$school) {
            return [
                'result' => false,
                'msg' => '该订单已删除'
            ];
        }

        $school = $school->toArray();
        $share = ConfigService::getInstance()->getServiceItem($school['nid']);

        $order_no = DataConversion::getInstance()->get_order_no();
        $fee = $share->price;
        $dur = DataConversion::getInstance()->getDays($school['start_time'], $school['end_time']);
        $price = $fee * $dur;
        $name = "【 " . $share->name . "报名】" . $order_no . '支付' . $price . '元';
        $orderParam = [
            'uid' => $uid,
            'rid' => $school['id'],
            'type' => 6,
            'order_no' => $order_no,
            'amount_real' => $price,
            'payment_type' => 0,
            'status' => 3,
            'order_remark' => $name
        ];

        if ($price == 0) {
            $orderParam['status'] = 4;
            $orderParam['payment_real'] = 0.00;
            $orderParam['payment_amount'] = 0.00;
            $orderParam['payment_remark'] = 'SUCCESS';
            $orderParam['payment_status'] = 1;
            $orderParam['payment_time'] = time();
            $res = AdjacentOlderModel::create()->update(['status' => 1], ['uid' => $uid, 'id' => $id]);
            if (!$res) {
                return [
                    'result' => false,
                    'msg' => '系统错误，请稍后重试'
                ];
            }
        } else {
            $appid = ConfigService::getInstance()->getSys("mxappid", 'wepay');
            $mxappid = ConfigService::getInstance()->getSys("mxminiappid", 'wepay');
            $mchid = ConfigService::getInstance()->getSys("mchid", 'wepay');
            $password = ConfigService::getInstance()->getSys("mxpassword", 'wepay');
            $cert = ConfigService::getInstance()->getSys("cert", 'wepay');
            $key = ConfigService::getInstance()->getSys("key", 'wepay');
            $notifyUrl = ConfigService::getInstance()->getSys("wenotify_url", 'wepay');
            $user = UserModel::create()->getUser(['id' => $uid]);
            if (!$user || $user->we_code == '') {
                return [
                    'result' => false,
                    'msg' => 'openidNotFound'
                ];
            }

            $res = Payment::getInstance()->mxWepay($appid, $mxappid, $mchid, $password, $cert, $key, $user->we_code, $order_no, $price * 100, $name, $notifyUrl, $ip);
            $result = $res->toArray();
        }

        $resOrder = OrderModel::create()->addOrder($orderParam);
        if (!$resOrder) {
            return [
                'result' => false,
                'msg' => '系统错误，请稍后重试'
            ];
        }

        return [
            'result' => true,
            'msg' => '成功',
            'data' => $result ?? 'success'
        ];
    }

    /**
     * @param $limit
     * @return array
     * @throws Exception
     * @throws Throwable
     */
    public function getServiceItems($limit): array
    {
        $list = ConfigShareItemModel::create()->where(['is_deleted' => 0])->limit($limit)->order("update_time")->all();

        if (empty($list)) {
            return [
                'result' => false,
                'msg' => '暂无服务'
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $list
        ];
    }

    /**
     * @param $tid
     * @param $limit
     * @param $page
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getShareLatticeGoods($tid, $limit, $page): array
    {
        $where = ['is_deleted' => 0];
        $model = ShareLatticeGoodsModel::create();
        $model->limit($limit * ($page - 1), $limit)->withTotalCount();
        if ($tid != 99) {
            $where['topic'] = $tid;
        }

        $model->order('id', "DESC");
        $list = $model->where($where)->all();
        $result = $model->lastQueryResult();
        // 总条数
        $total = $result->getTotalCount();
        if (empty($list)) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $data = [];
        foreach ($list as $item) {
            $user = StaffModel::create()->getUser(['id' => $item['sid']]);
            $data[] = [
                'id' => $item['id'],
                'avatar' => $user->avatar ?? '',
                'username' => $user->username ?? '物业中心',
                'from' => $item['from'],
                'theme' => ConfigService::getInstance()->getLatticeTopic($item['topic']),
                'content' => $item['content'],
                'images' => json_decode($item['images'], true),
                'time' => DataConversion::getInstance()->timeToDate($item['create_time']),
                'price' => $item['price'],
                'status' => $item['status'],
                'status_label' => $item['status'] == 1 ? '已转让' : ''
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $id
     * @return array
     * @throws \EasySwoole\Mysqli\Exception\Exception
     * @throws Throwable
     * @throws Exception
     */
    public function getLatticeDetail($id): array
    {
        $lattice = ShareLatticeGoodsModel::create()->getDynamic(['id' => $id]);
        if (!$lattice) {
            return [
                'result' => false,
                'msg' => '该数据不存在'
            ];
        }
        $item = $lattice->toArray();
        $data = [];
        $user = StaffModel::create()->getUser(['id' => $item['sid']]);
        $data['info'] = [
            'id' => $item['id'],
            'avatar' => $user->avatar ?? '',
            'username' => $user->username ?? '物业中心',
            'from' => $item['from'],
            'theme' => ConfigService::getInstance()->getLatticeTopic($item['topic']),
            'content' => $item['content'],
            'images' => json_decode($item['images'], true),
            'time' => DataConversion::getInstance()->timeToDate($item['create_time']),
            'price' => $item['price'],
            'status' => $item['status'],
            'status_label' => $item['status'] == 1 ? '已转让' : ''
        ];
        $order = ShareLatticeOrderModel::create()->where(['gid' => $id]);
        $data['order'] = [];
        if ($order) $data['order'] = $order->toArray();

        return [
            'result' => true,
            'msg' => ' 获取成功',
            'data' => $data
        ];

    }

    /**
     * @param $uid
     * @param $id
     * @param $name
     * @param $tel
     * @param $address
     * @param $ip
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function createOrder($uid, $id, $name, $tel, $address, $ip): array
    {
        $goods = ShareLatticeGoodsModel::create()->getDynamic(['id' => $id, 'status' => 0]);
        if (!$goods) {
            return [
                'result' => false,
                'msg' => '该商品已出售'
            ];
        }
        $par = [
            'uid' => $uid,
            'gid' => $id,
            'name' => $name,
            'tel' => $tel,
            'address' => $address
        ];

        $res = ShareLatticeOrderModel::create()->addAdjacent($par);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '下单失败，请稍后重试'
            ];
        }
        $parOrder = [
            'uid' => $uid,
            'type' => 7,
            'rid' => $id,
            'order_no' => DataConversion::getInstance()->get_order_no(),
            'amount_real' => $goods->price,
            'order_remark' => '【共享格子铺】' . $goods->content . '支付' . $goods->price . '元',
            'status' => 2
        ];

        $resOrder = OrderModel::create()->addOrder($parOrder);
        if (!$resOrder) {
            return [
                'result' => false,
                'msg' => '订单创建失败，请稍后重试'
            ];
        }

        $appid = ConfigService::getInstance()->getSys("mxappid", 'wepay');
        $mxappid = ConfigService::getInstance()->getSys("mxminiappid", 'wepay');
        $mchid = ConfigService::getInstance()->getSys("mchid", 'wepay');
        $password = ConfigService::getInstance()->getSys("mxpassword", 'wepay');
        $cert = ConfigService::getInstance()->getSys("cert", 'wepay');
        $key = ConfigService::getInstance()->getSys("key", 'wepay');
        $notifyUrl = ConfigService::getInstance()->getSys("wenotify_url", 'wepay');
        $user = UserModel::create()->getUser(['id' => $uid]);
        if (!$user || $user->we_code == '') {
            return [
                'result' => false,
                'msg' => 'openidNotFound'
            ];
        }

        $res = Payment::getInstance()->mxWepay($appid, $mxappid, $mchid, $password, $cert, $key, $user->we_code, $parOrder['order_no'], $parOrder['amount_real'] * 100, $parOrder['order_remark'], $notifyUrl, $ip);
        $result = $res->toArray();

        $resOrder = OrderModel::create()->update(['status' => 3], ['order_no' => $parOrder['order_no']]);
        if (!$resOrder) {
            return [
                'result' => false,
                'msg' => '系统错误，请稍后重试'
            ];
        }

        return [
            'result' => true,
            'msg' => '成功',
            'data' => $result ?? 'success'
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function delLattice($uid, $id): array
    {
        $res = ShareLatticeModel::create()->update(['is_deleted' => 1], ['uid' => $uid, 'id' => $id]);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '操作失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '操作成功',
            'data' => 'success'
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function assignLattice($uid, $id): array
    {
        $res = ShareLatticeModel::create()->update(['status' => 1], ['uid' => $uid, 'id' => $id]);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '操作失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '操作成功',
            'data' => 'success'
        ];
    }

    /**
     * @param $uid
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getMyComment($uid): array
    {
        $comment = ShareLatticeCommentModel::create()->where(['uid' => $uid, 'is_deleted' => 0])->all();
        if (empty($comment)) {
            return [
                'result' => false,
                'msg' => '暂无评论'
            ];
        }
        $ids = array_column($comment, 'gid');

        $list = ShareLatticeModel::create()->where('id', $ids, 'IN')->where(['is_deleted' => 0])->order('id', 'DESC')->all();
        $data = [];
        foreach ($list as $item) {
            $user = UserModel::create()->getUser(['id' => $item['uid']]);
            $data[] = [
                'id' => $item['id'],
                'avatar' => $user->avatar ?? '',
                'username' => $user->username ?? '匿名',
                'from' => $item['from'],
                'theme' => ConfigService::getInstance()->getLatticeTopic($item['topic']),
                'content' => $item['content'],
                'see' => $item['see'],
                'like' => $item['like'],
                'comment' => $item['comment'],
                'images' => json_decode($item['images'], true),
                'time' => DataConversion::getInstance()->timeToDate($item['create_time']),
                'price' => $item['price'],
                'status' => $item['status'],
                'status_label' => $item['status'] == 1 ? '已转让' : '',
                'contact_type' => $item['contact_type'],
                'contact' => $item['contact']
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getMyLike($uid): array
    {
        $like = ShareLatticeGoodModel::create()->where(['uid' => $uid, 'is_deleted' => 0])->all();
        if (!$like) {
            return [
                'result' => false,
                'msg' => '暂无点赞'
            ];
        }

        $ids = array_column($like, 'gid');

        $list = ShareLatticeModel::create()->where('id', $ids, 'IN')->where(['is_deleted' => 0])->order('id', 'DESC')->all();
        $data = [];
        foreach ($list as $item) {
            $user = UserModel::create()->getUser(['id' => $item['uid']]);
            $data[] = [
                'id' => $item['id'],
                'avatar' => $user->avatar ?? '',
                'username' => $user->username ?? '匿名',
                'from' => $item['from'],
                'theme' => ConfigService::getInstance()->getLatticeTopic($item['topic']),
                'content' => $item['content'],
                'see' => $item['see'],
                'like' => $item['like'],
                'comment' => $item['comment'],
                'images' => json_decode($item['images'], true),
                'time' => DataConversion::getInstance()->timeToDate($item['create_time']),
                'price' => $item['price'],
                'status' => $item['status'],
                'status_label' => $item['status'] == 1 ? '已转让' : '',
                'contact_type' => $item['contact_type'],
                'contact' => $item['contact']
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $status
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getLatticeOrder($uid, $status): array
    {
        $where = ['is_deleted' => 0, 'uid' => $uid];
        if ($status != 99) {
            $where['status'] = $status;
        }
        $model = ShareLatticeOrderModel::create();
        $list = $model->where($where)->order('id', "DESC")->all();
        if (empty($list)) {
            return [
                'result' => false,
                'msg' => '暂无订单'
            ];
        }
        $data = [];
        foreach ($list as $value) {
            $goods = ShareLatticeGoodsModel::create()->getDynamic(['id' => $value['gid']]);
            $goods = $goods->toArray();
            $order = OrderModel::create()->getOrder(['type' => 7, 'rid' => $value['gid']]);
            $user = UserModel::create()->getUser(['id' => $value['uid']]);
            $data[] = [
                'uid' => $user->id,
                'username' => $user->username,
                'avatar' => $user->avatar,
                'from' => $goods['from'],
                'theme' => ConfigService::getInstance()->getLatticeTopic($goods['topic']),
                'content' => $goods['content'],
                'images' => json_decode($goods['images'], true),
                'goods_create_time' => DataConversion::getInstance()->timeToDate($goods['create_time']),
                'price' => $goods['price'],
                'goods_status' => $goods['status'],
                'goods_status_label' => $goods['status'] == 1 ? '已转让' : '',
                'oid' => $order->id ?? 0,
                'name' => $value['name'],
                'address' => $value['address'],
                'tel' => $value['tel'],
                'older_status' => $value['status'],
                'older_create_time' => DataConversion::getInstance()->timeToDate($value['create_time'] ?? ''),
                'id' => $value['id'],
                'order_no' => $order->order_no ?? '',
                'amount_real' => $order->amount_real ?? '',
                'payment_trade' => $order->payment_trade ?? '-',
                'payment_status' => $order->payment_status ?? 0,
                'payment_amount' => $order->payment_amount ?? 0.00,
                'payment_remark' => $order->payment_remark ?? '-',
                'payment_time' => DataConversion::getInstance()->timeToDate($order->payment_time ?? ''),
                'order_status' => $order->status ?? 2,
                'order_create_time' => DataConversion::getInstance()->timeToDate($order->create_time ?? '')
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getLatticeOrderDetail($uid, $id): array
    {
        $older = ShareLatticeOrderModel::create()->getAdjacent(['id' => $id, 'uid' => $uid]);
        if (!$older) {
            return [
                'result' => false,
                'msg' => '该订单已失效'
            ];
        }

        $value = $older->toArray();
        $goods = ShareLatticeGoodsModel::create()->getDynamic(['id' => $value['gid']]);
        $goods = $goods->toArray();
        $order = OrderModel::create()->getOrder(['type' => 7, 'rid' => $value['gid']]);
        $user = UserModel::create()->getUser(['id' => $value['uid']]);
        $data = [
            'uid' => $user->id,
            'username' => $user->username,
            'avatar' => $user->avatar,
            'from' => $goods['from'],
            'theme' => ConfigService::getInstance()->getLatticeTopic($goods['topic']),
            'content' => $goods['content'],
            'images' => json_decode($goods['images'], true),
            'goods_create_time' => DataConversion::getInstance()->timeToDate($goods['create_time']),
            'price' => $goods['price'],
            'goods_status' => $goods['status'],
            'goods_status_label' => $goods['status'] != 0 ? '已转让/已下架' : '在售',
            'oid' => $order->id ?? 0,
            'name' => $value['name'],
            'address' => $value['address'],
            'tel' => $value['tel'],
            'older_status' => $value['status'],
            'older_create_time' => DataConversion::getInstance()->timeToDate($value['create_time'] ?? ''),
            'id' => $value['id'],
            'order_no' => $order->order_no ?? '',
            'amount_real' => $order->amount_real ?? '',
            'payment_trade' => $order->payment_trade ?? '-',
            'payment_status' => $order->payment_status ?? 0,
            'payment_amount' => $order->payment_amount ?? 0.00,
            'payment_remark' => $order->payment_remark ?? '-',
            'payment_time' => DataConversion::getInstance()->timeToDate($order->payment_time ?? ''),
            'order_status' => $order->status ?? 2,
            'order_create_time' => DataConversion::getInstance()->timeToDate($order->create_time ?? '')
        ];

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $key
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function searchLattice($key): array
    {
        $model = ShareLatticeGoodsModel::create();
        $list = $model->where(['is_deleted' => 0])->where("content", '%' . $key . '%', 'LIKE')->all();
        if (empty($list)) {
            return [
                'result' => false,
                'msg' => '暂无数据'
            ];
        }

        $data = [];
        foreach ($list as $item) {
            $user = StaffModel::create()->getUser(['id' => $item['sid']]);
            $data[] = [
                'id' => $item['id'],
                'avatar' => $user->avatar ?? '',
                'username' => $user->username ?? '物业中心',
                'from' => $item['from'],
                'theme' => ConfigService::getInstance()->getLatticeTopic($item['topic']),
                'content' => $item['content'],
                'images' => json_decode($item['images'], true),
                'time' => DataConversion::getInstance()->timeToDate($item['create_time']),
                'price' => $item['price'],
                'status' => $item['status'],
                'status_label' => $item['status'] == 1 ? '已转让' : ''
            ];
        }

        return [
            'result' => true,
            'msg' => '获取成功',
            'data' => $data
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function delSchool($uid, $id): array
    {
        $res = AdjacentSchoolModel::create()->update(['is_deleted' => 1], ['uid' => $uid, 'id' => $id]);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '操作失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '操作成功',
            'data' => 'success'
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function delOld($uid, $id): array
    {
        $res = AdjacentOlderModel::create()->update(['is_deleted' => 1], ['uid' => $uid, 'id' => $id]);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '操作失败'
            ];
        }
        return [
            'result' => true,
            'msg' => '操作成功',
            'data' => 'success'
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function delTool($uid, $id): array
    {
        $res = AdjacentToolModel::create()->update(['is_deleted' => 1], ['uid' => $uid, 'id' => $id]);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '操作失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '操作成功',
            'data' => 'success'
        ];
    }

    /**
     * @param $uid
     * @param $id
     * @return array
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function delKitchen($uid, $id): array
    {
        $res = AdjacentKitchenModel::create()->update(['is_deleted' => 1], ['uid' => $uid, 'id' => $id]);
        if (!$res) {
            return [
                'result' => false,
                'msg' => '操作失败'
            ];
        }

        return [
            'result' => true,
            'msg' => '操作成功',
            'data' => 'success'
        ];
    }
}